Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <style> #content { height: 100px; width: 100px; background-color: coral; padding: 15px; border: 10px solid black; margin: 10px; overflow: scroll; } </style> </head> <body> <p>Click the first button to return the scrollHeight and scrollWidth of div. Click the second button to set the width and height of div to the values returned from scrollHeight and scrollWidth.</p> <button onclick="getFunction()">Get scrollHeight and scrollWidth</button> <button onclick="setFunction()">Set height and width</button> <div id="content">Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..Some content..</div> <p id="demo"></p> <script> var elmnt = document.getElementById("content"); function getFunction() { document.getElementById("demo").innerHTML = "Height: " + elmnt.scrollHeight + "px" + "<br>Width: " + elmnt.scrollWidth + "px" ; } function setFunction() { elmnt.style.height = elmnt.scrollHeight + "px"; elmnt.style.width = elmnt.scrollWidth + "px"; } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_scrollheight3 by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:29:00 GMT --> </html>
Result:
Try it Yourself - © w3schools.com